package com.yzh.book.dao;

import com.yzh.book.model.BookInfo;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

@Component
public class BookDao {

    @Value("${num}")
    private Integer num;
    public List<BookInfo> mockData() {
        //理论上该方法从数据库中获取数据，现在用mock的方式
        List<BookInfo> bookInfos = new ArrayList<>();
        for (int i = 1; i <= num; i++) {
            BookInfo bookInfo = new BookInfo();
            bookInfo.setBookId(i);
            bookInfo.setBookName("图书" + i);
            bookInfo.setAuthor("作者" + i);
            bookInfo.setNumber("编号" + i);
            bookInfo.setPrice(new BigDecimal(i * 3));
            bookInfo.setPress("出版社" + i);
            if(i%5 == 0){
                bookInfo.setState(2);
            }else{
                bookInfo.setState(1);
            }
            bookInfos.add(bookInfo);
        }
        return bookInfos;
    }
}
